package edu.hunau.cxb.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.Arrays;
import java.util.Date;
import java.util.Map;

/**
 * @author hb
 * @create 2020-03-30 11:24
 */
@Controller
public class ResponseDataTestController {

    @RequestMapping("/testModelAndView")
    public ModelAndView testModelAndView(){
        ModelAndView mv = new ModelAndView();
        mv.setViewName("mv");

        //绑定数据
        //将数据存储到request对象中
        mv.addObject("time",new Date().toString());

        return mv;
    }


    @RequestMapping("/testMap")
    public String testMap(Map<String,Object> map){
        ///org.springframework.validation.support.BindingAwareModelMap
        System.out.println(map.getClass().getName());

        map.put("names", Arrays.asList("haoren","lucy","lili"));

        return "mv";

    }

    @RequestMapping("/testModel")
    public String testModel(Map<String,Object> map, Model model, ModelMap modelMap){
        System.out.println("map="+map.getClass().getName());
        System.out.println("model="+model.getClass().getName());
        System.out.println("modelMap="+modelMap.getClass().getName());

        map.put("map","Map");
        model.addAttribute("model","Model");
        modelMap.put("modelMap","ModelMap");


        return "mv";
    }
}
